package com.njuse_czf.kg.web.service.impl;

import com.njuse_czf.kg.web.request.QuestionQuery;
import com.njuse_czf.kg.web.service.KGGraphService;
import com.njuse_czf.kg.web.service.QuestionService;
import com.njuse_czf.kg.web.service.impl.handler.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private KGGraphService kgGraphService;

    @Override
    public String answer(QuestionQuery query) {
        String domain = query.getDomain();
        String question = query.getQuestion().trim();

        QuestionCtx questionCtx = new QuestionCtx();
        questionCtx.setDomain(domain);

        AbstractQuestionHandler handler = new HeaderHandler().builder()
                .addHandler(new AdvantageHandler())
                .addHandler(new AdvantageHandler())
                .addHandler(new AllowHandler())
                .addHandler(new ApplyToHandler())
                .addHandler(new AuthorHandler())
                .addHandler(new BelongToHandler())
                .addHandler(new BetterThanHandler())
                .addHandler(new BuildWithHandler())
                .addHandler(new ContainHandler())
                .addHandler(new CoverHandler())
                .addHandler(new DependOnHandler())
                .addHandler(new DisadvantageHandler())
                .addHandler(new EnableHandler())
                .addHandler(new EnableHandler())
                .addHandler(new FeatureHandler())
                .addHandler(new FunctionHandler())
                .addHandler(new HaveAPositiveEffectOnHandler())
                .addHandler(new HaveHandler())
                .addHandler(new IncludeHandler())
                .addHandler(new ManageHandler())
                .addHandler(new OfferHandler())
                .addHandler(new ProvideHandler())
                .addHandler(new RelateWithHandler())
                .addHandler(new ReplaceHandler())
                .addHandler(new SimilarToHandler())
                .addHandler(new SuitHandler())
                .addHandler(new SupportHandler())
                .addHandler(new UseHandler())
                .addHandler(new VersionHandler())
                .build();
        questionCtx.setCurrentHandler(handler);
        handler.handleQuestion(questionCtx, question, kgGraphService);

        return questionCtx.getAnswer();
    }
}
